package com.tm.d13_lambda;

import com.tm.d12_arrays.Student;

import java.util.Arrays;
import java.util.Comparator;
import java.util.function.IntToDoubleFunction;

/**
 * 2024/5/25 学习Lambda表达式 Cjj 16:33
 */
public class LambdaTest3 {
    public static void main(String[] args) {

        Student[] students = new Student[4];
        students [0] = new Student("蜘蛛精",169.5,23);
        students [1] = new Student("紫霞",163.8,26);
        students [2] = new Student("紫霞",163.8,26);
        students [3] = new Student("至尊宝",167.5,24);

        /**1.原始方法**/
        Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getAge()-o2.getAge();
            }
        });

        /**2.使用Lambda表达式的方法**/
//        Arrays.sort(students,(o1, o2) -> o1.getAge()-o2.getAge());
//     Arrays.sort(students,(o1,o2)->CompareByData.compareByAge(o1,o2));
    /*    Arrays.sort(students, (Student o1,Student o2)->{

                return Double.compare(o1.getHeight(), o2.getHeight());
            });
        System.out.println(Arrays.toString(students));
    }*/
      /*  Arrays.sort(students, ( o1, o2)->{

                return Double.compare(o1.getHeight(), o2.getHeight());
            });
        System.out.println(Arrays.toString(students));
    }*/
       Arrays.sort(students, ( o1, o2)-> Double.compare(o1.getHeight(), o2.getHeight()));
        System.out.println(Arrays.toString(students));

        /**3.使用静态方法**/
        Arrays.sort(students,CompareByData::compareByAge);
        System.out.println(Arrays.toString(students));


        /**4.使用实例方法**/
        //Arrays.sort(students,((o1, o2) ->o2.getAge()- o1.getAge() ));
        CompareByData compareByData = new CompareByData();
        //Arrays.sort(students,(o1,o2)->compareByData.compareByAgeDesc(o1,o2));//降序


        //实例方法降序引用
        Arrays.sort(students,compareByData::compareByAgeDesc);
        System.out.println(Arrays.toString(students));
    }
}
